package LeetCode;

import java.util.Collections;
import java.util.List;

public class LC_524_LongestWordinDictionarythroughDeleting {

    public static void main(String[] args) {

    }

    public class Solution {
        public String findLongestWord(String s, List<String> d) {
            Collections.sort(d);
            String result = "";
            for (String item : d)
                if (help(s, item) && item.length() > result.length()) result = item;
            return result;
        }

        private boolean help(String s, String t) {
            boolean flag = false;
            int i = 0, j = 0;
            while (i < s.length() && j < t.length()) {
                if (s.charAt(i) == t.charAt(j)) {
                    i++;
                    j++;
                } else i++;
            }
            if (j == t.length()) flag = true;
            return flag;
        }

    }
}